﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Runtime.Serialization;
using System.Configuration;
using System.Windows.Forms;
using System.Xml.Serialization;
using System.Data;
using System.Text.RegularExpressions;
using System.Net;

namespace LearnDrive
{
    public static class AShelp
    {
        
        private static clsMCI mp;
        public static string[] GetIP()
        {
            string tempip = "";
            string add = "";
            try
            {
                WebRequest wr = WebRequest.Create("http://1212.ip138.com/ic.asp");
                Stream s = wr.GetResponse().GetResponseStream();
                StreamReader sr = new StreamReader(s, Encoding.Default);
                string all = sr.ReadToEnd(); //读取网站的数据

                int start = all.IndexOf("您的IP是：[") + 7;
                int end = all.IndexOf("]", start);
                tempip = all.Substring(start, end - start);
                start = all.IndexOf("来自：") + 3;
                end = all.IndexOf("<", start);
                add = all.Substring(start, end - start);
                sr.Close();
                s.Close();
            }
            catch
            {
            }
            return new string[] { tempip, add };
        }
        public static void writeLog(string str)
        {
            if (!Directory.Exists("错误记录"))
            {
                Directory.CreateDirectory("错误记录");
            }


            using (StreamWriter sw = new StreamWriter(@"错误记录\ErrLog.txt", true))
            {
                sw.WriteLine(str);
                sw.WriteLine("---------------------------------------------------------");
                sw.Close();
            }
        }
        public static string FilterHTML(string html)
        {
            System.Text.RegularExpressions.Regex regex1 =
                  new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex2 =
                  new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex3 =
                  new System.Text.RegularExpressions.Regex(@" no[sS]*=",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex4 =
                  new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex5 =
                  new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex6 =
                  new System.Text.RegularExpressions.Regex(@"<img[^>]+>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex7 =
                  new System.Text.RegularExpressions.Regex(@"</p>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex8 =
                  new System.Text.RegularExpressions.Regex(@"<p>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            System.Text.RegularExpressions.Regex regex9 =
                  new System.Text.RegularExpressions.Regex(@"<[^>]*>",
                  System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            html = regex1.Replace(html, ""); //过滤<script></script>标记 
            html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性 
            html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件 
            html = regex4.Replace(html, ""); //过滤iframe 
            html = regex5.Replace(html, ""); //过滤frameset 
            html = regex6.Replace(html, ""); //过滤frameset 
            html = regex7.Replace(html, ""); //过滤frameset 
            html = regex8.Replace(html, ""); //过滤frameset 
            html = regex9.Replace(html, "");
            //html = html.Replace(" ", "");
            html = html.Replace("</strong>", "");
            html = html.Replace("<strong>", "");
            html = Regex.Replace(html, "[\f\t\v]", "");  //过滤回车换行制表符
            return html;
        }
        public static DataSet getTFZds(int KeMu1, int KeMu4, int HuiFu, int cccc, int aab, int ab, int def, int nums, string TiXing)
        {
            DataSet ds = null;
            StringBuilder sb = new StringBuilder();

            sb.Append("select top " + nums + " id,TiXing,NeiRong,JiangJie,DaAn,ShengYin,TuPian,A,B,C,D from Tbl_TiKu where TiXing='" + TiXing + "' ");
            if (KeMu1 != 0)
                sb.AppendFormat(" and KM1='{0}'", KeMu1);
            if (KeMu4 != 0)
                sb.AppendFormat(" and KM4='{0}'", KeMu4);
            if (HuiFu != 0)
                sb.AppendFormat(" and HuiFu='{0}'", HuiFu);
            if (cccc != 0)
                sb.AppendFormat(" and cccc='{0}'", cccc);
            if (aab != 0)
                sb.AppendFormat(" and aab='{0}'", aab);
            if (ab != 0)
                sb.AppendFormat(" and ab='{0}'", ab);
            if (def != 0)
                sb.AppendFormat(" and def='{0}'", def);
            sb.Append(" and jiaoan='0'");
            sb.Append(" order by right(cstr(rnd(-int(rnd(-timer())*100+id)))*1000,2),id");

            ds = DbHelperOleDb.Query(sb.ToString());
            return ds;
        }
        public static DataSet getTFZ(int KeMu1, int KeMu4, int HuiFu, int cccc, int aab, int ab, int def)
        {
            DataSet ds = null;
            DataSet temp = null;
            ds = new DataSet();
            int pdnum = 0, dxnum = 0, duoxnum = 0;
            if (KeMu1 != 0)
            {
                pdnum = 40;
                dxnum = 60;
                if (def != 0)
                {
                    pdnum = 20;
                    dxnum = 30;
                }

                temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, pdnum, "1");
                DataTable dt = temp.Tables[0].Copy();
                ds.Tables.Add(dt);
                temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, dxnum, "2");
                ds.Tables[0].Merge(temp.Tables[0]);
                return ds;
            }
            if (KeMu4 != 0)
            {
                pdnum = 22;
                dxnum = 23;
                duoxnum = 5;
                if (aab != 0 || ab != 0)
                {
                    pdnum = 10;
                    dxnum = 30;
                    duoxnum = 10;
                }
                temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, pdnum, "1");
                DataTable dt = temp.Tables[0].Copy();
                ds.Tables.Add(dt);
                temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, dxnum, "2");
                ds.Tables[0].Merge(temp.Tables[0]);
                if (duoxnum != 0)
                {
                    temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, duoxnum, "3");
                    ds.Tables[0].Merge(temp.Tables[0]);

                }

                return ds;
            }
            if (HuiFu != 0)
            {
                pdnum = 20;
                dxnum = 30;
                if (aab != 0 || ab != 0)
                {
                    pdnum = 40;
                    dxnum = 50;
                    duoxnum = 10;
                }
                temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, pdnum, "1");
                DataTable dt = temp.Tables[0].Copy();
                ds.Tables.Add(dt);
                temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, dxnum, "2");
                ds.Tables[0].Merge(temp.Tables[0]);
                if (duoxnum != 0)
                {
                    temp = getTFZds(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, duoxnum, "3");
                    ds.Tables[0].Merge(temp.Tables[0]);

                }
                return ds;
            }
            return ds;
        }
        public static void insertDel(string ids, string GengXinShiJian, string sign, string tablename)
        {
            int id = 0;
            int.TryParse(ids, out id);
            if (id > 0)
            {
                string sql = string.Format("select count(*) from " + tablename + " where id={0}", id);
                object o = DbHelperOleDb.GetSingle(sql);
                string sqlin;
                if (o != null)
                {
                    int i = 0;
                    int.TryParse(o.ToString(), out i);
                    if (i == 0)
                    {
                        sqlin = string.Format("insert into {3}(id,GengXinShiJian,sign) values({0},'{1}','{2}')", id, GengXinShiJian, sign, tablename);
                    }
                    else
                    {
                        sqlin = string.Format("update {3} set GengXinShiJian='{1}',sign='{2}' where id={0}", id, GengXinShiJian, sign, tablename);
                    }
                }
                else
                {
                    sqlin = string.Format("update {3} set GengXinShiJian='{1}',sign='{2}' where id={0}", id, GengXinShiJian, sign, tablename);
                }
                DbHelperOleDb.ExecuteSql(sqlin);
                string dbtablename = tablename.Replace("del", "");
                DbHelperOleDb.ExecuteSql("delete from " + dbtablename + " where id=" + id);
            }
        }
        public static void insertTP(string fname, byte[] fneirong, string sign, string gengxinshijian)
        {


            string sql = string.Format("select count(*) from tbl_shengyintp where fname='{0}'", fname);
            object o = TPDbHelperOleDb.GetSingle(sql);
            string sqlin;
            if (o != null)
            {
                int i = 0;
                int.TryParse(o.ToString(), out i);
                if (i == 0)
                {
                    sqlin = string.Format("insert into tbl_shengyintp(fname,fneirong,sign,gengxinshijian) values('{0}',@fs,'{1}','{2}')", fname, sign, gengxinshijian);
                }
                else
                {
                    sqlin = string.Format("update tbl_shengyintp set fneirong=@fs,sign='{1}',gengxinshijian='{2}' where fname='{0}'", fname, sign, gengxinshijian);
                }
            }
            else
            {
                sqlin = string.Format("update tbl_shengyintp set fneirong=@fs,sign='{1}',gengxinshijian='{2}' where fname='{0}'", fname, sign, gengxinshijian);
            }

            TPDbHelperOleDb.ExecuteSqlInsertImg(sqlin, fneirong);
            string path = Application.StartupPath + "\\temp\\" + fname;
            if (File.Exists(path))
            {
                try
                {
                    File.Delete(path);
                }
                catch (Exception)
                {

                }
            }

        }

        public static void insertGonggao(string ids, string biaoti, string neirong, string zuozhe, string shijian, string jiezhiriqi, string gengxinshijian)
        {
            int id = 0;
            int.TryParse(ids, out id);
            if (id > 0)
            {
                string sql = string.Format("select count(*) from tbl_gonggao where id={0}", id);
                object o = DbHelperOleDb.GetSingle(sql);
                string sqlin;
                if (o != null)
                {
                    int i = 0;
                    int.TryParse(o.ToString(), out i);
                    if (i == 0)
                    {
                        sqlin = string.Format("insert into tbl_gonggao(id,biaoti,neirong,zuozhe,shijian,jiezhiriqi,gengxinshijian) values({0},'{1}','{2}','{3}','{4}','{5}','{6}')", id, biaoti, neirong, zuozhe, shijian, jiezhiriqi, gengxinshijian);
                    }
                    else
                    {
                        sqlin = string.Format("update tbl_gonggao set biaoti='{1}',neirong='{2}',zuozhe='{3}',shijian='{4}',jiezhiriqi='{5}',gengxinshijian='{6}' where id={0}", id, biaoti, neirong, zuozhe, shijian, jiezhiriqi, gengxinshijian);
                    }
                }
                else
                {
                    sqlin = string.Format("update tbl_gonggao set biaoti='{1}',neirong='{2}',zuozhe='{3}',shijian='{4}',jiezhiriqi='{5}',gengxinshijian='{6}' where id={0}", id, biaoti, neirong, zuozhe, shijian, jiezhiriqi, gengxinshijian);
                }

                DbHelperOleDb.ExecuteSql(sqlin);
            }
        }

        public static void insertZhangjies(string ids, string bianhao, string mingcheng, string kemu1, string kemu4, string huifu, string cccc, string aab, string ab, string def, string jichu, string qianghua, string sucheng, string jiaoan, string zhuanxiang, string zhangjie, string sign, string gengxinshijian, string iswenmang)
        {
            int id = 0;
            int.TryParse(ids, out id);
            if (id > 0)
            {
                string sql = string.Format("select count(*) from tbl_zhangjies where id={0}", id);
                object o = DbHelperOleDb.GetSingle(sql);
                string sqlin;
                if (o != null)
                {
                    int i = 0;
                    int.TryParse(o.ToString(), out i);
                    if (i == 0)
                    {
                        sqlin = string.Format("insert into tbl_zhangjies(id,bianhao,mingcheng,kemu1,kemu2,huifu,cccc,aab,ab,def,jichu,qianghua,sucheng,jiaoan,zhuanxiang,zhangjie,sign,gengxinshijian,iswenmang) values({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}')", id, bianhao, mingcheng, kemu1, kemu4, huifu, cccc, aab, ab, def, jichu, qianghua, sucheng, jiaoan, zhuanxiang, zhangjie, sign, gengxinshijian, iswenmang);
                    }
                    else
                    {
                        sqlin = string.Format("update tbl_zhangjies set bianhao='{1}', mingcheng='{2}', kemu1='{3}', kemu2='{4}', huifu='{5}', cccc='{6}', aab='{7}', ab='{8}', def='{9}', jichu='{10}', qianghua='{11}', sucheng='{12}', jiaoan='{13}', zhuanxiang='{14}', zhangjie='{15}', sign='{16}', gengxinshijian='{17}', iswenmang='{18}' where id={0}", id, bianhao, mingcheng, kemu1, kemu4, huifu, cccc, aab, ab, def, jichu, qianghua, sucheng, jiaoan, zhuanxiang, zhangjie, sign, gengxinshijian, iswenmang);
                    }
                }
                else
                {
                    sqlin = string.Format("update tbl_zhangjies set bianhao='{1}', mingcheng='{2}', kemu1='{3}', kemu2='{4}', huifu='{5}', cccc='{6}', aab='{7}', ab='{8}', def='{9}', jichu='{10}', qianghua='{11}', sucheng='{12}', jiaoan='{13}', zhuanxiang='{14}', zhangjie='{15}', sign='{16}', gengxinshijian='{17}', iswenmang='{18}' where id={0}", id, bianhao, mingcheng, kemu1, kemu4, huifu, cccc, aab, ab, def, jichu, qianghua, sucheng, jiaoan, zhuanxiang, zhangjie, sign, gengxinshijian, iswenmang);
                }

                DbHelperOleDb.ExecuteSql(sqlin);
            }
        }

        public static void insertTiKu(string ids, string zhangjie, string zhangjie_s, string tixing, string neirong, string jiangjie, string daan, string shengyin, string tupian, string jichu, string qianghua, string sucheng, string jiaoan, string zhuanxiang, string zhangjie_k, string cccc, string aab, string ab, string def, string huifu, string km1, string km4, string gengxinshijian, string a, string b, string c, string d, string e, string f, string iswenmang)
        {
            int id = 0;
            int.TryParse(ids, out id);
            if (id > 0)
            {
                string sql = string.Format("select count(*) from tbl_tiku where id={0}", id);
                object o = DbHelperOleDb.GetSingle(sql);
                string sqlin;
                if (o != null)
                {
                    int i = 0;
                    int.TryParse(o.ToString(), out i);
                    if (i == 0)
                    {
                        sqlin = string.Format("insert into tbl_tiku(id,zhangjie,zhangjie_s,tixing,neirong,jiangjie,daan,shengyin,tupian,jichu,qianghua,sucheng,jiaoan,zhuanxiang,zhangjie_k,cccc,aab,ab,def,huifu,km1,km4,gengxinshijian,a,b,c,d,e,f,iswenmang) values({0},'{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}')", id, zhangjie, zhangjie_s, tixing, neirong, jiangjie, daan, shengyin, tupian, jichu, qianghua, sucheng, jiaoan, zhuanxiang, zhangjie_k, cccc, aab, ab, def, huifu, km1, km4, gengxinshijian, a, b, c, d, e, f, iswenmang);
                    }
                    else
                    {
                        sqlin = string.Format("update tbl_tiku set zhangjie='{1}', zhangjie_s='{2}', tixing='{3}', neirong='{4}', jiangjie='{5}', daan='{6}', shengyin='{7}', tupian='{8}', jichu='{9}', qianghua='{10}', sucheng='{11}', jiaoan='{12}', zhuanxiang='{13}', zhangjie_k='{14}', cccc='{15}', aab='{16}', ab='{17}', def='{18}', huifu='{19}', km1='{20}', km4='{21}', gengxinshijian='{22}', a='{23}', b='{24}', c='{25}', d='{26}', e='{27}', f='{28}', iswenmang='{29}' where id={0}", id, zhangjie, zhangjie_s, tixing, neirong, jiangjie, daan, shengyin, tupian, jichu, qianghua, sucheng, jiaoan, zhuanxiang, zhangjie_k, cccc, aab, ab, def, huifu, km1, km4, gengxinshijian, a, b, c, d, e, f, iswenmang);
                    }
                }
                else
                {
                    sqlin = string.Format("update tbl_tiku set zhangjie='{1}', zhangjie_s='{2}', tixing='{3}', neirong='{4}', jiangjie='{5}', daan='{6}', shengyin='{7}', tupian='{8}', jichu='{9}', qianghua='{10}', sucheng='{11}', jiaoan='{12}', zhuanxiang='{13}', zhangjie_k='{14}', cccc='{15}', aab='{16}', ab='{17}', def='{18}', huifu='{19}', km1='{20}', km4='{21}', gengxinshijian='{22}', a='{23}', b='{24}', c='{25}', d='{26}', e='{27}', f='{28}', iswenmang='{29}' where id={0}", id, zhangjie, zhangjie_s, tixing, neirong, jiangjie, daan, shengyin, tupian, jichu, qianghua, sucheng, jiaoan, zhuanxiang, zhangjie_k, cccc, aab, ab, def, huifu, km1, km4, gengxinshijian, a, b, c, d, e, f, iswenmang);
                }

                DbHelperOleDb.ExecuteSql(sqlin);
            }
        }
        public static DateTime getMaxTime(string sel, string table)
        {
            DateTime dt = new DateTime(2016, 1, 1, 0, 0, 0);
            string sql = "select " + sel + " from " + table;
            object o = null;
            try
            {
                o = DbHelperOleDb.GetSingle(sql);
            }
            catch (Exception ex)
            {
                sql = "Create TABLE [" + table + "]([ID] int, [GengXinShiJian] DATETIME, [sign] VarChar)";
                DbHelperOleDb.ExecuteSql(sql);
                return dt;
            }
            if (o != null)
            {
                DateTime.TryParse(o.ToString(), out dt);
            }
            DateTime.TryParse(dt.ToString("yyyy-MM-dd HH:mm:ss"), out dt);
            return dt;
        }
        public static DateTime getMaxTimeTS(string sel, string table)
        {
            DateTime dt = new DateTime(2016, 1, 1, 0, 0, 0);
            string sql = "select " + sel + " from " + table;
            object o = TPDbHelperOleDb.GetSingle(sql);
            if (o != null)
            {
                DateTime.TryParse(o.ToString(), out dt);
            }
            DateTime.TryParse(dt.ToString("yyyy-MM-dd HH:mm:ss"), out dt);
            return dt;
        }

        public static DataSet getInfo()
        {
            string sql = "select NeiRong from Tbl_GongGao where jiezhiriqi>#" + DateTime.Now.ToShortDateString() + "#";
            return DbHelperOleDb.Query(sql);

        }
        public static void insertCT(int id)
        {
            string sql = string.Format("insert into Tbl_CuoTi(ID,userid) values({0},'{1}')", id, Myinfo.username);
            DbHelperOleDb.ExecuteSql(sql);
        }
        public static void delCT(int id)
        {
            string sql = string.Format("delete from Tbl_CuoTi where userid='{1}' and id={0}", id, Myinfo.username);
            DbHelperOleDb.ExecuteSql(sql);
        }
        public static int getCTCount()
        {
            int i = 0;
            string sql = string.Format("select count(*) from Tbl_CuoTi where userid='{0}'", Myinfo.username);
            int.TryParse(DbHelperOleDb.GetSingle(sql).ToString(), out i);
            return i;
        }
        public static DataSet getCT()
        {
            string sql = string.Format("select Tbl_TiKu.id,TiXing,NeiRong,JiangJie,DaAn,ShengYin,TuPian,A,B,C,D from Tbl_CuoTi INNER JOIN Tbl_TiKu ON Tbl_CuoTi.ID = Tbl_TiKu.ID where Tbl_CuoTi.userid='{0}'", Myinfo.username);
            return DbHelperOleDb.Query(sql);
        }
        public static void clearCT()
        {
            string sql = string.Format("delete from Tbl_CuoTi  where userid='{0}'", Myinfo.username);
            DbHelperOleDb.ExecuteSql(sql);
        }
        public static string getPic(string name)
        {
            string path = Application.StartupPath + "\\temp\\" + name;
            if (File.Exists(path))
                return path;
            else
            {
                try
                {
                    string sql = string.Format("select FNeiRong from Tbl_ShengYinTP where Fname='{0}'", name);
                    DataSet ds = TPDbHelperOleDb.Query(sql);
                    if (ds != null && ds.Tables[0].Rows.Count > 0)
                    {
                        byte[] data = (byte[])(ds.Tables[0].Rows[0]["FNeiRong"]);
                        File.WriteAllBytes(path, data);
                        //MemoryStream ms = new MemoryStream(data);
                        //System.Drawing.Image newImage = System.Drawing.Image.FromStream(ms);
                        //newImage.Save(path);
                        return path;
                    }
                    else
                    {
                        return "";
                    }
                }
                catch (Exception ex)
                {

                    return "";
                }
            }
        }
        public static bool IsInRand(int[] arr, int index)
        {
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] == index) return true;
            }
            return false;
        }
        public static int[] GetRandomNum(int num, int maxnum)
        {
            Random r = new Random();
            //对数组进行随机排序的算法:随机选择两个位置，将两个位置上的值交换
            //交换的次数,这里使用数组的长度作为交换次数
            int[] arr = new int[maxnum];
            int[] rarr = new int[num];
            for (int i = 0; i < maxnum; i++)
            {
                arr[i] = i;
            }
            int count = arr.Length;
            //开始交换
            for (int i = 0; i < num; i++)
            {
                //生成两个随机数位置
                int randomNum1 = r.Next(0, maxnum - i);
                int temp;
                //交换两个随机数位置的值
                temp = arr[randomNum1];
                arr[randomNum1] = arr[maxnum - i - 1];
                rarr[i] = temp;
            }
            return rarr;
        }
        public static string[] GetRandomArray(string[] arr)
        {
            Random r = new Random();
            //对数组进行随机排序的算法:随机选择两个位置，将两个位置上的值交换
            //交换的次数,这里使用数组的长度作为交换次数
            //string[] arr = new string[] { "A","B","C","D"};
            int count = arr.Length;
            //开始交换
            for (int i = 0; i < count; i++)
            {
                //生成两个随机数位置
                int randomNum1 = r.Next(0, arr.Length);
                int randomNum2 = r.Next(0, arr.Length);
                //定义临时变量
                string temp;
                //交换两个随机数位置的值
                temp = arr[randomNum1];
                arr[randomNum1] = arr[randomNum2];
                arr[randomNum2] = temp;
            }
            return arr;
        }
        public static DataSet getT(string bm, bool isrand)
        {
            DataSet ds = null;
            StringBuilder sb = new StringBuilder();
            sb.Append("select id,TiXing,NeiRong,JiangJie,DaAn,ShengYin,TuPian,A,B,C,D from Tbl_TiKu ");
            sb.AppendFormat("where ZhangJie_S like '%{0}%'", bm);

            if (isrand)
                sb.Append(" order by right(cstr(rnd(-int(rnd(-timer())*100+id)))*1000,2)");
            else
                sb.Append(" order by id");
            ds = DbHelperOleDb.Query(sb.ToString());
            return ds;
        }
        public static DataSet getT100(int KeMu1, int KeMu4, int HuiFu, int cccc, int aab, int ab, int def, int sucheng, int jichu, int qianghua, int zhuanxiang, int zhangjie, int isWenMang)
        {
            DataSet ds = null;
            StringBuilder sb = new StringBuilder();
            sb.Append("select top 100 id,TiXing,NeiRong,JiangJie,DaAn,ShengYin,TuPian,A,B,C,D from Tbl_TiKu where 1=1 ");
            if (KeMu1 != 0)
                sb.AppendFormat(" and KM1='{0}'", KeMu1);
            if (KeMu4 != 0)
                sb.AppendFormat(" and KM4='{0}'", KeMu4);
            if (HuiFu != 0)
                sb.AppendFormat(" and HuiFu='{0}'", HuiFu);
            if (cccc != 0)
                sb.AppendFormat(" and cccc='{0}'", cccc);
            if (aab != 0)
                sb.AppendFormat(" and aab='{0}'", aab);
            if (ab != 0)
                sb.AppendFormat(" and ab='{0}'", ab);
            if (def != 0)
                sb.AppendFormat(" and def='{0}'", def);
            if (sucheng != 0)
                sb.AppendFormat(" and sucheng='{0}'", sucheng);

            if (jichu != 0)
                sb.AppendFormat(" and jichu='{0}'", jichu);
            if (qianghua != 0)
                sb.AppendFormat(" and qianghua='{0}'", qianghua);
            if (zhuanxiang != 0)
                sb.AppendFormat(" and zhuanxiang='{0}'", zhuanxiang);
            if (zhangjie != 0)
                sb.AppendFormat(" and zhangjie='{0}'", zhangjie);
            if (isWenMang != 0)
                sb.AppendFormat(" and isWenMang='{0}'", isWenMang);
            sb.Append(" and jiaoan='0'");
            sb.Append(" order by right(cstr(rnd(-int(rnd(-timer())*100+id)))*1000,2),id");
            ds = DbHelperOleDb.Query(sb.ToString());
            return ds;
        }
        /// <summary>
        /// 得到列表
        /// </summary>
        /// <param name="KeMu1"></param>
        /// <param name="KeMu4"></param>
        /// <param name="HuiFu"></param>
        /// <param name="cccc"></param>
        /// <param name="aab"></param>
        /// <param name="ab"></param>
        /// <param name="def"></param>
        /// <param name="sucheng"></param>
        /// <param name="sucheng600"></param>
        /// <param name="jichu"></param>
        /// <param name="qianghua"></param>
        /// <param name="zhuangxiang"></param>
        /// <param name="zhangjie"></param>
        /// <param name="isWenMang"></param>
        /// <returns></returns>
        public static DataSet getList(int KeMu1, int KeMu4, int HuiFu, int cccc, int aab, int ab, int def, int sucheng, int jichu, int qianghua, int zhuanxiang, int zhangjie, int isWenMang)
        {
            DataSet ds = null;
            StringBuilder sb = new StringBuilder();
            sb.Append("select id,BianHao,MingCheng from Tbl_ZhangJieS where 1=1");
            if (KeMu1 != 0)
                sb.AppendFormat(" and KeMu1='{0}'", KeMu1);
            if (KeMu4 != 0)
                sb.AppendFormat(" and KeMu2='{0}'", KeMu4);
            if (HuiFu != 0)
                sb.AppendFormat(" and HuiFu='{0}'", HuiFu);
            if (cccc != 0)
                sb.AppendFormat(" and cccc='{0}'", cccc);
            if (aab != 0)
                sb.AppendFormat(" and aab='{0}'", aab);
            if (ab != 0)
                sb.AppendFormat(" and ab='{0}'", ab);
            if (def != 0)
                sb.AppendFormat(" and def='{0}'", def);
            if (sucheng != 0)
                sb.AppendFormat(" and sucheng='{0}'", sucheng);
            if (jichu != 0)
                sb.AppendFormat(" and jichu='{0}'", jichu);
            if (qianghua != 0)
                sb.AppendFormat(" and qianghua='{0}'", qianghua);
            if (zhuanxiang != 0)
                sb.AppendFormat(" and zhuanxiang='{0}'", zhuanxiang);
            if (zhangjie != 0)
                sb.AppendFormat(" and zhangjie='{0}'", zhangjie);
            if (isWenMang != 0)
                sb.AppendFormat(" and isWenMang='{0}'", isWenMang);
            sb.Append(" and sign='0'");
            sb.Append(" order by BianHao");
            ds = DbHelperOleDb.Query(sb.ToString());
            return ds;

        }
        public static void Play(string file)
        {
            string path = Application.StartupPath + "\\" + file;
            if (!File.Exists(path))
            {
                return;
            }
            mp = new clsMCI();
            mp.FileName = path;
            try
            {
                mp.play();

            }
            catch
            {
                //MessageBox.Show("出错错误!");
            }
        }
        public static void Stop()
        {
            try
            {
                if (mp != null)
                    mp.StopT();

            }
            catch
            {
                //MessageBox.Show("出错错误!");
            }
        }
        public static void Pause()
        {
            try
            {
                if (mp != null)
                    mp.Puase();

            }
            catch
            {
                //MessageBox.Show("出错错误!");
            }
        }
        public static string LoadTXT(string path)
        {
            string html = "";
            if (!File.Exists(path))
            {
                return "";
            }
            html = File.ReadAllText(path, Encoding.Default);
            return html;
        }
        public static void SaveTXT(string html, string path)
        {
            File.WriteAllText(path, html);
        }
        public static List<string> Load(string file)
        {
            List<string> list = new List<string>();
            string path = Application.StartupPath + "\\" + Myinfo.snameword + @"\" + file;
            if (!File.Exists(path))
            {
                return null;
            }
            XmlSerializer serializer = new XmlSerializer(list.GetType());
            using (XmlReader reader = new XmlTextReader(path))
            {
                return (List<string>)serializer.Deserialize(reader);
            }
        }
        public static void Save(string name1, string name2, string name3, string name4, string file)
        {
            List<string> graph = new List<string> {
                name1,
                name2,
                name3,
                name4
            };
            string path = Application.StartupPath + "\\" + Myinfo.snameword;
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string filename = path + @"\" + file;
            XmlSerializer serializer = new XmlSerializer(graph.GetType());
            using (XmlWriter writer = new XmlTextWriter(filename, Encoding.UTF8))
            {
                serializer.Serialize(writer, graph);
            }
        }
        public static void UpdateAppConfig(string newKey, string newValue)
        {
            bool isModified = false;
            foreach (string key in ConfigurationManager.AppSettings)
            {
                if (key == newKey)
                {
                    isModified = true;
                }
            }
            Configuration config =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (isModified)
            {
                config.AppSettings.Settings.Remove(newKey);
            }
            config.AppSettings.Settings.Add(newKey, newValue);
            config.Save(ConfigurationSaveMode.Modified);
            ConfigurationManager.RefreshSection("appSettings");
        }
        public static string DateDiff(ref TimeSpan ts)
        {
            string dateDiff = null;
            ts = ts.Subtract(new TimeSpan(0, 0, 1));
            dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒";
            return dateDiff;
        }
        public static string DateDiff(DateTime DateTime1, DateTime DateTime2)
        {
            string dateDiff = null;
            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();
            dateDiff = ts.Days.ToString() + "天" + ts.Hours.ToString() + "小时" + ts.Minutes.ToString() + "分钟" + ts.Seconds.ToString() + "秒";
            return dateDiff;
        }
        public static string DateDiffshort(DateTime DateTime1, DateTime DateTime2)
        {
            string dateDiff = null;
            TimeSpan ts1 = new TimeSpan(DateTime1.Ticks);
            TimeSpan ts2 = new TimeSpan(DateTime2.Ticks);
            TimeSpan ts = ts1.Subtract(ts2).Duration();
            dateDiff = ts.Minutes.ToString() + ":" + ts.Seconds.ToString();
            return dateDiff;
        }

    }
}
